﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ArticleWeb
{
    public class TimeUitl
    {
        public static DateTimeRange GetTimeRange(string time)
        {
            var range = new DateTimeRange();
            if (string.IsNullOrEmpty(time))
                return range;
            var r = time.Split(new char[] { '$' }, 2);
            if (r.Length != 2)
            {
                throw new Exception("时间格式不正确");
            }
            if (string.IsNullOrEmpty(r[0]))
                range.TimeFrom = null;
            else
            {
                range.TimeFrom = DateTime.Parse(r[0]).Date;
            }
            if (string.IsNullOrEmpty(r[1]))
                range.TimeTo = null;
            else
            {
                range.TimeTo = DateTime.Parse(r[1]).Date.AddDays(1).AddSeconds(-1);
            }
            return range;
        }
    }

    public class DateTimeRange
    {
        public DateTime? TimeFrom { get; set; }
        public DateTime? TimeTo { get; set; }
    }
}